import { Injectable } from '@nestjs/common';
import { User, UserDocument } from './schemas/user.schema';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { CreateUserDTO } from './dto/user.dto';

@Injectable()
export class UserService {
  constructor(
    //依赖注入
    @InjectModel(User.name)
    private readonly userModel: Model<UserDocument>,
  ) {}

  //注册
  async createOne(userInfo: CreateUserDTO) {
    const createdUser = new this.userModel(userInfo);
    return await createdUser.save();
  }

  //登录
  async fineOne(username: string, password: string) {
    return await this.userModel.findOne({ username, password });
  }
}
